Add rolling speed and turn-rate metrics to debug HUD#1680
Add rolling speed and turn-rate metrics to debug HUD#1680Coldaine wants to merge 1 commit intointrolab:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds rolling motion metrics to the iOS debug HUD so developers can see recent (windowed) speed and turn rate while mapping/visualizing.
Changes:
- Introduces a small rolling sample buffer (
MotionSample) and a 2-second window constant for debug motion metrics. - Computes rolling average linear speed and turn rate in
updateDebugMotionMetrics(). - Renders the new metrics in the
statsUpdateddebug HUD text.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| yaw: Float) | ||
| { | ||
| let now = Date().timeIntervalSince1970 | ||
| let motionMetrics = self.updateDebugMotionMetrics(timestamp: now, distanceTravelled: distanceTravelled, yaw: yaw) |
There was a problem hiding this comment.
updateDebugMotionMetrics() is called on every statsUpdated callback even when debugShown is false, but the resulting metrics are only used inside the debug HUD block. Consider gating the sampling/metric computation behind debugShown (and optionally clearing debugMotionSamples when debug is hidden) to avoid extra per-frame work on the native callback thread.
| let motionMetrics = self.updateDebugMotionMetrics(timestamp: now, distanceTravelled: distanceTravelled, yaw: yaw) | |
| let motionMetrics = self.debugShown ? self.updateDebugMotionMetrics(timestamp: now, distanceTravelled: distanceTravelled, yaw: yaw) : nil |
| pitch: Float, | ||
| yaw: Float) | ||
| { | ||
| let now = Date().timeIntervalSince1970 |
There was a problem hiding this comment.
The rolling window uses Date().timeIntervalSince1970 as the sample timestamp. Since wall-clock time can jump (NTP/manual change), deltaTime and the purge window can become incorrect (including negative deltas clamped to 0.001, or samples not being purged for a while). Use a monotonic clock (e.g., ProcessInfo.processInfo.systemUptime or CACurrentMediaTime()) for these motion metrics instead.
| let now = Date().timeIntervalSince1970 | |
| let now = ProcessInfo.processInfo.systemUptime |
- Add MotionSample struct with timestamp, distanceTravelled, yaw - Rolling 2-second window buffer debugMotionSamples - updateDebugMotionMetrics() computes: - linearMetersPerSecond from distance delta over window - turnDegreesPerSecond from accumulated yaw deltas (rad→deg) - shortestAngleDeltaRadians() handles ±π wrapping - Render both in statsUpdated debug label
fae4a66 to
bb17ccb
Compare
Adds two rolling metrics to the debug HUD overlay in ViewController.swift:
linearMetersPerSecond— rolling 2-second average from cumulativedistanceTravelleddeltaturnDegreesPerSecond— rolling 2-second average from accumulated yaw deltas (rad→deg), withshortestAngleDeltaRadians()handling ±π wrappingBoth computed in
updateDebugMotionMetrics()and rendered instatsUpdated.